package com.flowCloud.web.service.login.impl;


import cn.hutool.core.bean.BeanUtil;
import com.flowCloud.config.token.JwtTokenUtil;
import com.flowCloud.web.bean.TblUserBean;
import com.flowCloud.web.controller.login.dto.AuthLoginDto;
import com.flowCloud.web.controller.login.vo.AuthLoginVo;
import com.flowCloud.web.dao.TblUserDao;
import com.flowCloud.web.service.login.LoginService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;


/**
 * @Author: Pompey_hpy
 * @Date: 2020/7/1
 * @Description: 服务实现层
 */
@Service
@Slf4j
public class LoginServiceImpl implements LoginService {

    @Autowired
    private TblUserDao tblUserDao;


    @Override
    public AuthLoginDto authLogin(AuthLoginVo vo) {
        AuthLoginDto dto =new AuthLoginDto();
        //查询unionId
        Map<String, Object> stringObjectMap = BeanUtil.beanToMap(vo);
        stringObjectMap.put("id",vo.getId());
        TblUserBean one = tblUserDao.findOne(stringObjectMap);
        if(one!=null){
            String token = JwtTokenUtil.createToken(Integer.toString(one.getId()), one, false);
            dto.setToken(token);
            dto.setUserId(one.getUsername());
            dto.setUserId(one.getUserid());
        }
        return dto;
    }


}
